package com.superdry.guide;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.drysurper.R;
import com.superdry.guide.fragment.GuideFragment_01;
import com.superdry.guide.fragment.GuideFragment_02;
import com.superdry.guide.fragment.GuideFragment_03;
import com.superdry.main.MainActivity;
import com.superdry.utils.SPHelper;

/**
 * @author JM_Soldier@163.com
 */
public class GuideActivity extends FragmentActivity {
	private ViewPager viewPage;
	private GuideFragment_01 mFragment1;
	private GuideFragment_02 mFragment2;
	private GuideFragment_03 mFragment3;
	private PagerAdapter mPgAdapter;
	private RadioGroup dotLayout;
	private List<Fragment> mListFragment = new ArrayList<Fragment>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide);
		initView();
		viewPage.setOnPageChangeListener(new MyPagerChangeListener());

	}

	private void initView() {
		dotLayout = (RadioGroup) findViewById(R.id.advertise_point_group);
		viewPage = (ViewPager) findViewById(R.id.viewpager);
		mFragment1 = new GuideFragment_01();
		mFragment2 = new GuideFragment_02();
		mFragment3 = new GuideFragment_03();
		mListFragment.add(mFragment1);
		mListFragment.add(mFragment2);
		mListFragment.add(mFragment3);
		mPgAdapter = new ViewPagerAdapter(getSupportFragmentManager(), mListFragment);
		viewPage.setAdapter(mPgAdapter);

		//已进入介绍页，下次不进入
		SPHelper.putBoolean(GuideActivity.this, "isFirst", true);
	}

	public class MyPagerChangeListener implements OnPageChangeListener {

		public void onPageSelected(int position) {
		}

		public void onPageScrollStateChanged(int arg0) {

		}

		public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
			((RadioButton) dotLayout.getChildAt(position)).setChecked(true);
		}

	}
}
